package com.dw.best_base

import android.app.AlertDialog
import android.content.DialogInterface
import com.kingja.loadsir.core.LoadService
import com.kingja.loadsir.core.LoadSir
import com.loper7.base.ui.BaseActivity
import com.loper7.base.utils.img.ImageLoad
import com.loper7.base.utils.loadsir.*
import kotlinx.android.synthetic.main.activity_loading.*


/**
 * @author LOPER7
 * @date 2018/12/11 16:50
 * @Description:
 */
class LoadingActivity : BaseActivity() {

    private val status: Array<String> = arrayOf("LOADING", "SUCCESS","EMPTY", "ERROR", "TIMEOUT", "PLACEHOLDER DETAILS", "PLACEHOLDER LIST")
    private lateinit var loadService: LoadService<*>

    override fun getContentViewId(): Int {
        return R.layout.activity_loading
    }

    override fun initData() {

    }

    override fun initView() {
        loadService = LoadSir.getDefault().register(root_content) {
            showMessage("click onReload")
        }

        ImageLoad.loadRound(context, 5, image, "http://dingyue.nosdn.127.net/OZmS7kw9zBHsTIZwFFNj=eXhWpTtuJIrIsJLBWoo47Cl=1541130964946.jpg"
                , R.drawable.ic_default_empty)
    }

    override fun initListener() {
        titleBar.setOnMenuListener {
            AlertDialog.Builder(context).setItems(status) { dialog: DialogInterface, position: Int ->
                when (position) {
                    0 -> loadService.showCallback(LoadingCallback::class.java)
                    1 -> loadService.showSuccess()
                    2 -> loadService.showCallback(EmptyCallback::class.java)
                    3 -> loadService.showCallback(ErrorCallback::class.java)
                    4 -> loadService.showCallback(TimeoutCallback::class.java)
                    5 -> loadService.showCallback(PlaceholderDetailsCallback::class.java)
                    6 -> loadService.showCallback(PlaceholderListCallback::class.java)
                }
                dialog.cancel()
            }.show()

        }


    }

}

